package com.cykj.pos.service.impl;

import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.ToolCashbackTemplate;
import com.cykj.pos.domain.WithdrawalRateTemplate;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import com.cykj.pos.mapper.SettlementRateTemplateMapper;
import com.cykj.pos.domain.SettlementRateTemplate;
import com.cykj.pos.service.ISettlementRateTemplateService;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 结算模板Service业务层处理
 *
 * @author weijianbo
 * @date 2025-01-20
 */
@Service
public class SettlementRateTemplateServiceImpl extends ServiceImpl<SettlementRateTemplateMapper, SettlementRateTemplate> implements ISettlementRateTemplateService {

    @Resource
    private SettlementRateTemplateMapper settlementRateTemplateMapper;

    @Override
    public List<SettlementRateTemplate> queryList(SettlementRateTemplate settlementRateTemplate) {
        LambdaQueryWrapper<SettlementRateTemplate> lqw = Wrappers.lambdaQuery();
        if (settlementRateTemplate.getCreditRate() != null){
            lqw.eq(SettlementRateTemplate::getCreditRate ,settlementRateTemplate.getCreditRate());
        }
        if (settlementRateTemplate.getDebitFee() != null){
            lqw.eq(SettlementRateTemplate::getDebitFee ,settlementRateTemplate.getDebitFee());
        }
        if (settlementRateTemplate.getDebitCap() != null){
            lqw.eq(SettlementRateTemplate::getDebitCap ,settlementRateTemplate.getDebitCap());
        }
        if (settlementRateTemplate.getAdjustmentShare() != null){
            lqw.eq(SettlementRateTemplate::getAdjustmentShare ,settlementRateTemplate.getAdjustmentShare());
        }
        if (settlementRateTemplate.getQrCodeRate() != null){
            lqw.eq(SettlementRateTemplate::getQrCodeRate ,settlementRateTemplate.getQrCodeRate());
        }
        if (settlementRateTemplate.getD0Fee() != null){
            lqw.eq(SettlementRateTemplate::getD0Fee ,settlementRateTemplate.getD0Fee());
        }
        if (StringUtils.isNotBlank(settlementRateTemplate.getVar1())){
            lqw.eq(SettlementRateTemplate::getVar1 ,settlementRateTemplate.getVar1());
        }
        if (StringUtils.isNotBlank(settlementRateTemplate.getVar2())){
            lqw.eq(SettlementRateTemplate::getVar2 ,settlementRateTemplate.getVar2());
        }
        if (StringUtils.isNotBlank(settlementRateTemplate.getVar3())){
            lqw.eq(SettlementRateTemplate::getVar3 ,settlementRateTemplate.getVar3());
        }
        return this.list(lqw);
    }

    @Override
    public BigDecimal getSettlementCreditRateMinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementCreditRateMinByMerchId(merchId);
    }

    @Override
    public BigDecimal getSettlementDebitRateMinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementDebitRateMinByMerchId(merchId);
    }

    @Override
    public BigDecimal getSettlementDebitCapMinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementDebitCapMinByMerchId(merchId);
    }

    @Override
    public BigDecimal getSettlementCommissionMinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementCommissionMinByMerchId(merchId);
    }

    @Override
    public BigDecimal getSettlementQrCodeRateMinMinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementQrCodeRateMinMinByMerchId(merchId);
    }

    @Override
    public BigDecimal getSettlementD0MinByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementD0MinByMerchId(merchId);
    }

    @Override
    public int checkIsThereSnByMerchId(Long merchId) {
        return settlementRateTemplateMapper.checkIsThereSnByMerchId(merchId);
    }

    @Override
    public List<SettlementRateTemplate> getSettlementRateTemplateByMerchId(Long merchId) {
        return settlementRateTemplateMapper.getSettlementRateTemplateByMerchId(merchId);
    }

    @Override
    public AjaxResult getWithdrawalTemplateList(WithdrawalRateTemplate withdrawalRateTemplate) {
        List<WithdrawalRateTemplate> withdrawalRateTemplates = settlementRateTemplateMapper.getWithdrawalTemplateList(withdrawalRateTemplate);
        return AjaxResult.success("提现模板列表", withdrawalRateTemplates);
    }

    @Override
    public AjaxResult backWithdrawalTemplateDeatil(WithdrawalRateTemplate withdrawalRateTemplate) {
        withdrawalRateTemplate = settlementRateTemplateMapper.backWithdrawalTemplateDeatil(withdrawalRateTemplate);
        return AjaxResult.success("提现模板明细",withdrawalRateTemplate);
    }

    @Override
    public AjaxResult backToolCashbackTemplateList() {
        List<ToolCashbackTemplate> toolCashbackTemplateList = settlementRateTemplateMapper.backToolCashbackTemplateList();
        return AjaxResult.success("返现模板列表", toolCashbackTemplateList);
    }

    @Override
    public AjaxResult backToolCashbackTemplateDetail(ToolCashbackTemplate toolCashbackTemplate) {
        toolCashbackTemplate = settlementRateTemplateMapper.backToolCashbackTemplateDetail(toolCashbackTemplate);
        return AjaxResult.success("返现模板明细",toolCashbackTemplate);
    }
}
